from ...models import *

# 判断prefix是否被使用
def is_prefix_used(prefix_entity):
    if Unit.objects.filter(prefix=prefix_entity,valid_flag=True).count() > 0:
        return True,"删除失败：单位词头被单位使用"
    return False,""

# 判断basic_dimension是否被使用
def is_basic_dimension_used(basic_dimension_entity):
    dimensionmap_list = DimensionMap.objects.filter(basic_dimension=basic_dimension_entity)
    dimension_list = set([dimensionmap.dimension for dimensionmap in dimensionmap_list if dimensionmap.dimension.valid_flag])
    if len(dimension_list) > 0:
        return True,"删除失败：基本量纲被量纲使用"
    return False,""

# 判断dimension是否被使用
def is_dimension_used(dimension_entity):
    # dimension是否被unit使用
    if Unit.objects.filter(dimension=dimension_entity,valid_flag=True).count() > 0:
        return True,"删除失败：量纲被单位使用"
    # dimension是否被quantity使用
    if Quantity.objects.filter(dimension=dimension_entity,valid_flag=True).count() > 0:
        return True,"删除失败：量纲被量使用"
    return False,""
    
# 判断unit是否被使用
def is_unit_used(unit_entity):
    # unit是否被unit使用
    if Unit.objects.filter(root_unit=unit_entity,valid_flag=True).count() > 0:
        return True,"删除失败：单位被单位使用"
    return False,""
    